package com.shootingGame.testClasses
{
	import com.common.physics.CollisionDetection;
	import com.common.testClasses.MasterTest;
	import com.common.testClasses.Test;
	
	import flash.display.MovieClip;
	import flash.geom.Rectangle;
	import flash.utils.getDefinitionByName;

	public class CollisionDetectionTest extends Test
	{
		public static const CIRCLE_RECT_NUM_CASES : int = 50;
		
		public function CollisionDetectionTest()
		{
			super();
		}
		
		override public function runTestFunctions():void{
			allTestsPositive = true;
			trace("Class: CollisionDetection");
			circleRectangleIntersection_Test();
		}
		
		private function circleRectangleIntersection_Test() : void {
			var numCorrect:int = 0;
			var numWrong_FromRandomSet:int = 0;
			trace("Function : circleRectangleIntersection");
			var caseMc:MovieClip;
			var classDef:Class;
			var rect:Rectangle;
			var rectMc:MovieClip;
			var circleMc:MovieClip;
			
			var radius:Number;
			var rectLeft:Number;
			var rectTop:Number;
			var rectRight:Number;
			var rectBottom:Number;
			
			var circCentreX:Number;
			var circCentreY:Number;
			var cMc:MovieClip;
			var rMc:MovieClip;
			var case1:MovieClip;
			
			var i : int = 1;
			var n : int = CIRCLE_RECT_NUM_CASES;
			for(i; i <= n; i++) {
				trace("Case ", i);
				if(i<=49){
					classDef = flash.utils.getDefinitionByName("CollisionDetectionCircRectCase"+i) as Class;
					caseMc = new classDef();
					rectMc = caseMc.rect;
					circleMc = caseMc.circle;
					
					radius = circleMc.width/2.0;
					rectLeft = rectMc.x - rectMc.width/2.0;
					rectRight = rectMc.x + rectMc.width/2.0;
					rectTop = rectMc.x - rectMc.height/2.0;
					rectBottom = rectMc.x + rectMc.height/2.0;
					
					if(i<=8 || (i >=22 && i<=41)){
					//These cases are for Assert FALSE, meaning that the function is supposed to return FALSE.
						if(!CollisionDetection.circleRectangleIntersection(radius, circleMc.x, circleMc.y, rectLeft, rectTop, rectRight, rectBottom)){
							allTestsPositive = false;
							numCorrect++;
							trace("CORRECT");
						}
						else
							trace("W-R-O-N-G");
					}
					else{
						//Assert TRUE.
						if(!CollisionDetection.circleRectangleIntersection(radius, circleMc.x, circleMc.y, rectLeft, rectTop, rectRight, rectBottom)){
							allTestsPositive = false;
							trace("W-R-O-N-G");	
						}
						else{
							numCorrect++;
							trace("CORRECT");
						}
										
					}
				}
				else{
					circCentreX = (-75) + Math.random() * (150);
					circCentreY = (-75) + Math.random() * (150);
					if(!CollisionDetection.circleRectangleIntersection(radius, circCentreX, circCentreY, -35, -35, 35, 35)){
						allTestsPositive = false;
						numWrong_FromRandomSet++;
						case1 = new CollisionDetectionCircRectCase1();
						cMc = case1.circle;
						rMc = case1.rect;
						
						cMc.x = circCentreX;
						cMc.y = circCentreY;
						rMc.x = 0;
						rMc.y = 0;
						case1.x = numWrong_FromRandomSet*80;
						case1.y = numWrong_FromRandomSet*50;
						MasterTest.MASTERTEST.addChild(case1);
						trace("W-R-O-N-G");	
					}
					else{
						numCorrect++;
						trace("CORRECT");
					}
				}
			}
			trace("\nCorrect : " + numCorrect + "/" + CIRCLE_RECT_NUM_CASES);
		}
		
		
		
	}
}